<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="function和objectfunction123456789var str = (()=&amp;gt; &amp;#123;    var count = 0;    function sum () &amp;#123; return ++count; &amp;#125;;    function reduce () &amp;#123;return --count;&amp;#125;;    return &amp;#123;">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript之Function函数">
<meta property="og:url" content="http://yoursite.com/2020/12/08/JavaScript之Function函数/index.html">
<meta property="og:site_name" content="春风自是人间客">
<meta property="og:description" content="function和objectfunction123456789var str = (()=&amp;gt; &amp;#123;    var count = 0;    function sum () &amp;#123; return ++count; &amp;#125;;    function reduce () &amp;#123;return --count;&amp;#125;;    return &amp;#123;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-12-08T13:25:25.755Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript之Function函数">
<meta name="twitter:description" content="function和objectfunction123456789var str = (()=&amp;gt; &amp;#123;    var count = 0;    function sum () &amp;#123; return ++count; &amp;#125;;    function reduce () &amp;#123;return --count;&amp;#125;;    return &amp;#123;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: "",
      labels: ""
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/12/08/JavaScript之Function函数/">





  <title>JavaScript之Function函数 | 春风自是人间客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">春风自是人间客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">是非成败转头空，青山依旧在，几度夕阳红。</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-program">
          <a href="/categories/program" rel="section">
            
            程序
          </a>
        </li>
      
        
        <li class="menu-item menu-item-reading">
          <a href="/categories/reading" rel="section">
            
            阅读
          </a>
        </li>
      
        
        <li class="menu-item menu-item-idea">
          <a href="/categories/idea" rel="section">
            
            想法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
            关于我
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/12/08/JavaScript之Function函数/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="彭丹丹">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://upload.jianshu.io/users/upload_avatars/830956/debe5156eed7?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="春风自是人间客">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">JavaScript之Function函数</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-12-08T15:44:34+08:00">
                2020-12-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/program/" itemprop="url" rel="index">
                    <span itemprop="name">program</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  798
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4
                </span>
              
            </div>
          

          
          
        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="function和object"><a href="#function和object" class="headerlink" title="function和object"></a>function和object</h1><h2 id="function"><a href="#function" class="headerlink" title="function"></a>function</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">var str = (()=&gt; &#123;</span><br><span class="line">    var count = 0;</span><br><span class="line">    function sum () &#123; return ++count; &#125;;</span><br><span class="line">    function reduce () &#123;return --count;&#125;;</span><br><span class="line">    return &#123;</span><br><span class="line">        sum,</span><br><span class="line">        reduce</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p>此时的str是个function</p>
<p>简化下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">var str = (()=&gt; &#123;</span><br><span class="line">    var count = 0;</span><br><span class="line">    return &#123;</span><br><span class="line">        sum : ()=&gt;&#123;return ++count;&#125;,</span><br><span class="line">        reduce : ()=&gt;&#123;return --count;&#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)();</span><br><span class="line">str.sum(); // 1</span><br></pre></td></tr></table></figure>
<p>此时的str是已经立即执行函数了，返回的是Object，是{sum:f,reduce:f}，注意，这里的str是获取不到count的，只有return的数据能获取到。</p>
<h2 id="Object"><a href="#Object" class="headerlink" title="Object"></a>Object</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">var obj = &#123;</span><br><span class="line">    count:0,</span><br><span class="line">    sum : ()=&gt;&#123;return ++obj.count;&#125;,</span><br><span class="line">    reduce : ()=&gt;&#123;return --obj.count;&#125;</span><br><span class="line">&#125;</span><br><span class="line">obj.sum(); // 1</span><br></pre></td></tr></table></figure>
<p>这里的obj是Object，不同于str的是，它能获取到count，object里面的所有数据都能获取到。</p>
<h2 id="区别"><a href="#区别" class="headerlink" title="区别"></a>区别</h2><ul>
<li>Function只有return的方法才能获取到（闭包）</li>
<li>Function执行后返回的是对象</li>
</ul>
<h1 id="JavaScript函数调用及this参数"><a href="#JavaScript函数调用及this参数" class="headerlink" title="JavaScript函数调用及this参数"></a>JavaScript函数调用及this参数</h1><p>JS有4种方式调用函数</p>
<ul>
<li>作为一个函数(<code>function</code>)——<code>fn()</code>直接被调用</li>
<li>作为一个方法(<code>methods</code>)——<code>obj.fn()</code>，关联在对象上调用，实现面向对象编程</li>
<li>作为一个构造函数(<code>constructor</code>)——<code>new Fn()</code>，实例化一个新的对象</li>
<li>通过<code>apply</code>或<code>call</code>方法调用</li>
</ul>
<p>对应的this的指向：</p>
<ul>
<li>函数调用：<code>window</code>或<code>undefined</code></li>
<li>方法调用：obj对象</li>
<li>构造函数调用：实例化的对象</li>
<li><code>aplly</code>或<code>call</code>：第一个参数</li>
</ul>
<p>详解：</p>
<h2 id="函数调用"><a href="#函数调用" class="headerlink" title="函数调用"></a>函数调用</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">function fn()&#123;</span><br><span class="line">    console.log(this);</span><br><span class="line">&#125;</span><br><span class="line">fn(); // window</span><br></pre></td></tr></table></figure>
<p>严格模式下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">function fn()&#123;</span><br><span class="line">    &quot;use strict&quot;</span><br><span class="line">    console.log(this);</span><br><span class="line">&#125;</span><br><span class="line">fn(); // undefined</span><br></pre></td></tr></table></figure>
<h2 id="方法调用"><a href="#方法调用" class="headerlink" title="方法调用"></a>方法调用</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">var obj = &#123;</span><br><span class="line">    fn : function()&#123;</span><br><span class="line">        console.log(this);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line">obj.fn() // 返回obj对象：&#123;fn: ƒ&#125;</span><br></pre></td></tr></table></figure>
<h2 id="构造函数调用"><a href="#构造函数调用" class="headerlink" title="构造函数调用"></a>构造函数调用</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">function Cat(x,y)&#123;</span><br><span class="line">    this.x = x;</span><br><span class="line">    this.y = y;</span><br><span class="line">    console.log(this);</span><br><span class="line">&#125;</span><br><span class="line">var c = new Cat(1,2);</span><br><span class="line"></span><br><span class="line">c // Cat&#123;x:1,y:2&#125; 指向c对象</span><br></pre></td></tr></table></figure>
<p>es6写法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">class Point&#123;</span><br><span class="line">    constructor(x,y)&#123;</span><br><span class="line">        this.x = x;</span><br><span class="line">        this.y = y;</span><br><span class="line">        console.log(this);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">var p = new Point(1,2)</span><br><span class="line"></span><br><span class="line">p // Point&#123;x:1,y:2&#125; 指向p对象</span><br></pre></td></tr></table></figure>
<h2 id="aplly或call"><a href="#aplly或call" class="headerlink" title="aplly或call"></a>aplly或call</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">var name = &apos;张三&apos;;</span><br><span class="line">var age = &apos;24&apos;;</span><br><span class="line">var obj = &#123;</span><br><span class="line">    name: this.name, // 此处的this指向window</span><br><span class="line">    objAge: this.age, // 此处的this指向window</span><br><span class="line">    fun: function(fm,t)&#123;</span><br><span class="line">        console.log(this)</span><br><span class="line">        console.log(this.name+&apos;年龄 &apos;+this.age + &apos; 来自&apos;+fm+&apos; 去往&apos;+t); // 此处的fm和t就是要传入的参数</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">var pd = &#123;</span><br><span class="line">    name: &apos;彭丹&apos;,</span><br><span class="line">    age:18</span><br><span class="line">&#125;</span><br><span class="line">obj.fun.call(pd,&apos;长沙&apos;,&apos;上海&apos;); // 彭丹 年龄18 来自长沙 去往上海</span><br><span class="line">obj.fun.apply(pd,[&apos;长沙&apos;,&apos;上海&apos;]); // 彭丹 年龄18 来自长沙 去往上海</span><br><span class="line">obj.fun.bind(pd,&apos;长沙&apos;,&apos;上海&apos;)(); // 彭丹 年龄18 来自长沙 去往上海</span><br><span class="line">obj.fun.bind(pd,[&apos;长沙&apos;,&apos;上海&apos;])(); // 彭丹 年龄18 来自长沙上海 去往undefined</span><br></pre></td></tr></table></figure>
<p><code>this</code>打印出来全都是<code>{name: &quot;彭丹&quot;, age: 18}</code>，就是第一个参数。</p>
<h1 id="函数构造器"><a href="#函数构造器" class="headerlink" title="函数构造器"></a>函数构造器</h1><p>与<code>构造函数</code>名字类似，但无太大关系。</p>
<p>普通生成</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">var p = new Function(&apos;x&apos;,&apos;y&apos;,&apos;return x+y&apos;);</span><br><span class="line">p(2,3)</span><br></pre></td></tr></table></figure>
<p>动态生成</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">createFunction()&#123;</span><br><span class="line">    let arr = Array.from(arguments);</span><br><span class="line">    var params = arr.splice(0,arr.length-1);</span><br><span class="line">    var body = arr[0];</span><br><span class="line">    return new Function(params,body);</span><br><span class="line">&#125;,</span><br><span class="line">test()&#123;</span><br><span class="line">    var sum = this.createFunction(&apos;x&apos;,&apos;y&apos;,&apos;return x + y&apos;);</span><br><span class="line">    var chen = this.createFunction(&apos;x&apos;,&apos;y&apos;,&apos;return x * y&apos;);</span><br><span class="line">    console.log(sum(3,2)) // 5</span><br><span class="line">    console.log(chen(3,2)) // 6</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
<h1 id="函数生成器-generator"><a href="#函数生成器-generator" class="headerlink" title="函数生成器(generator)"></a>函数生成器(generator)</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">function* test()&#123;</span><br><span class="line">    console.log(1);</span><br><span class="line">    yield;</span><br><span class="line">    console.log(2);</span><br><span class="line">&#125;</span><br><span class="line">let item = test();</span><br><span class="line">item.next();</span><br><span class="line">setTimeout(()=&gt;&#123;</span><br><span class="line">    item.next();</span><br><span class="line">&#125;,3000)</span><br><span class="line">1</span><br><span class="line">隔3秒后</span><br><span class="line">2</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/12/08/JavaScript之运行机制/" rel="next" title="JavaScript之运行机制">
                <i class="fa fa-chevron-left"></i> JavaScript之运行机制
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zODk2OC8xNTQ5Ng=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://upload.jianshu.io/users/upload_avatars/830956/debe5156eed7?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240" alt="彭丹丹">
            
              <p class="site-author-name" itemprop="name">彭丹丹</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">183</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#function和object"><span class="nav-number">1.</span> <span class="nav-text">function和object</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#function"><span class="nav-number">1.1.</span> <span class="nav-text">function</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Object"><span class="nav-number">1.2.</span> <span class="nav-text">Object</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#区别"><span class="nav-number">1.3.</span> <span class="nav-text">区别</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JavaScript函数调用及this参数"><span class="nav-number">2.</span> <span class="nav-text">JavaScript函数调用及this参数</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#函数调用"><span class="nav-number">2.1.</span> <span class="nav-text">函数调用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#方法调用"><span class="nav-number">2.2.</span> <span class="nav-text">方法调用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#构造函数调用"><span class="nav-number">2.3.</span> <span class="nav-text">构造函数调用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#aplly或call"><span class="nav-number">2.4.</span> <span class="nav-text">aplly或call</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#函数构造器"><span class="nav-number">3.</span> <span class="nav-text">函数构造器</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#函数生成器-generator"><span class="nav-number">4.</span> <span class="nav-text">函数生成器(generator)</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">彭丹丹</span>

  
</div>


	<div class="powered-by">
	<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
	  本站访客数:<span id="busuanzi_value_site_uv"></span>
	</span>
	</div>
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  

  

  

  undefined
  
  <!-- 页面爆炸效果 -->
  
<script src="/live2dw/lib/L2Dwidget.min.js?0c58a1486de42ac6cc1c59c7d98ae887"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/tororo.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true}});</script></body>
</html>
